<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //第二题
        (function() {
            console.log("我会立即执行");
        })()
        //第三题
        var func1 = function() {
            console.log("func1");
        }

        var func2 = function() {
            console.log("func2");
        }

        var func3 = function() {
            console.log("func3");
        }

        func3(func2);
        //第四题
        //         4. 做一个家族继承
        // object-fruit(可以吃)--(apple(果皮是红色),
        // banana(果皮是黄色),
        // watermelon(果皮是绿色))
        var fruit = function() {}
        fruit.prototype.eat = function() {
            console.log("可以吃");
        }

        var apple = function() {

        }
        apple.prototype = new fruit();
        apple.prototype.red = function() {
            console.log("果皮是红色的");
        }
        var banana = function() {

        }
        banana.prototype = new fruit();
        banana.prototype.yellow = function() {
            console.log("果皮是黄色的");
        }
        var watermelon = function() {

        }
        watermelon.prototype = new fruit();
        watermelon.prototype.green = function() {
            console.log("果皮是绿色的");
        }
        var fruit = new fruit();
        fruit.eat();

        var a = new apple();
        a.red();
        var w = new watermelon();
        w.green();
        var y = new banana();
        y.yellow();

        //第五题
        var a = {
            name: "李明",
            age: 19,
        }
        var b = {
            country: "中国",
            street: "番禺区",
        }
        var extend = function() {
            for (temp in b) {
                a[temp] = b[temp];
            }
        }
        extend(a, b);
        console.log(a);
        //第六题
        var sum = function() {
            var args = arguments; //他会存储传进去的参数
            var total = 0;
            for (var i = 0; i < args.length; i++) {
                total = total + args[i];
            }
            return total;
        }
        console.log(sum(1, 2, 3));
    </script>
</body>

</html>